using System;
using System.Data;
namespace Xmobile.DB
{
    public class StoredProcedures
    {
        private MainDB _db;

        public StoredProcedures(MainDB db)
        {
            _db = db;
        }

        public MainDB Database
        {
            get { return _db; }
        }

        protected DataTable CreateDataTable(IDbCommand command)
        {
            return _db.CreateDataTable(command);
        }

        protected DataSet CreateDataSet(IDbCommand command)
        {
            return _db.CreateDataSet(command);
        }

        #region ContentCrawler
        public DataTable ContentCrawler_Select_by_CatID(int CatID)
        {

            IDbCommand cmd = _db.CreateCommand("ContentCrawler_Select_by_CatID", true);
            _db.AddParameter(cmd, "CatID", DbType.Int32, CatID);
            DataTable table = _db.CreateDataTable(cmd);
            return table;

            
        }
        #endregion

        #region Apps
        public DataTable Apps_Select_by_CatID(int CatID)
        {

            IDbCommand cmd = _db.CreateCommand("Apps_Select_by_CatID", true);
            _db.AddParameter(cmd, "CatID", DbType.Int32, CatID);
            DataTable table = _db.CreateDataTable(cmd);
            return table;


        }

        public DataTable Apps_Select_List_Padding(int CatID, int PageIndex, int PageSize)
        {

            IDbCommand cmd = _db.CreateCommand("Apps_Select_List_Padding", true);
            _db.AddParameter(cmd, "CatID", DbType.Int32, CatID);
            _db.AddParameter(cmd, "PageIndex", DbType.Int32, PageIndex);
            _db.AddParameter(cmd, "PageSize", DbType.Int32, PageSize);
            DataTable table = _db.CreateDataTable(cmd);
            return table;


        }

        public void Apps_Insert(string AppName, string AppDes, string AppContent, string AppImage, string AppIcon, string AppLinkDownload, 
            string AppPartner, string AppSize, string AppDownloadCount, int AppCatId, string AppCategory)
        {
            IDbCommand cmd = _db.CreateCommand("Apps_Insert", true);
            _db.AddParameter(cmd, "AppName", DbType.String, AppName);
            _db.AddParameter(cmd, "AppDes", DbType.String, AppDes);
            _db.AddParameter(cmd, "AppContent", DbType.String, AppContent);
            _db.AddParameter(cmd, "AppImage", DbType.String, AppImage);
            _db.AddParameter(cmd, "AppIcon", DbType.String, AppIcon);
            _db.AddParameter(cmd, "AppLinkDownload", DbType.String, AppLinkDownload);
            _db.AddParameter(cmd, "AppPartner", DbType.String, AppPartner);
            _db.AddParameter(cmd, "AppSize", DbType.String, AppSize);
            _db.AddParameter(cmd, "AppDownloadCount", DbType.String, AppDownloadCount);
            _db.AddParameter(cmd, "AppCategory", DbType.String, AppCategory);
            _db.AddParameter(cmd, "AppCatId", DbType.Int32, AppCatId);
            
            DataTable table = _db.CreateDataTable(cmd);
        }

        #endregion

        #region 
        public DataTable Category_Select_by_CatID(int CatID)
        {
            IDbCommand cmd = _db.CreateCommand("vc_SelectCategoryByID", true);
            _db.AddParameter(cmd, "iCat_ID", DbType.Int32, CatID);
          
            DataTable table = _db.CreateDataTable(cmd);
            return table;
        }

        public DataTable Apps_Select_by_AppID(int AppID)
        {
            IDbCommand cmd = _db.CreateCommand("Apps_Select_by_AppID", true);
            _db.AddParameter(cmd, "AppID", DbType.Int32, AppID);

            DataTable table = _db.CreateDataTable(cmd);
            return table;
        }

        public void Apps_DownloadFile_AppID(int AppID)
        {
            IDbCommand cmd = _db.CreateCommand("Apps_DownloadFile_AppID", true);
            _db.AddParameter(cmd, "AppID", DbType.Int32, AppID);

            _db.CreateDataTable(cmd);
            
        }


        #endregion
    }
}